using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class YuanlinPager : Pager
    {
        private int aquacultureKebieId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.AquacultureKebieId);
        private string character = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.Character);
        private string queryText = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.QueryText);
        private int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);
        private string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);
        private int commentId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CommentId);
        private string tradeType = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.TradeType);
        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);
        private int appCategoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.AppCategoryId);
        private int area = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.Area);
        private int level = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.Level);
        private int provinceId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.ProvinceId);
        private int cityId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CityId);
        private int townId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.TownId);
        private int smallTownId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.SmallTownId);
        private string companyName = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.CompanyName);
        private string mobilePhoneKey = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.MobilePhoneKey);
        private int companyType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CompanyType);
        private int zicaiTopLevelCategoryID = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.ZicaiTopLevelCategoryID);
        private int zicaiSecondLevelCategoryID = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.ZicaiSecondLevelCategoryID);
        private int kind = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.Kind);
        private int defaultIndex = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.DefaultIndex);
        private int upNewsCategoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.UpNewsCategoryId);
        private int miaoMuCategoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.MiaoMuCategoryId);
        private int productCategoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.ProductCategoryId);
        private string orderBy = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.OrderBy);
        private string ascStr = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.Asc);

        private string pager = "";
        public string Pager
        {
            get { return pager; }
            set { pager = value; }
        }

        protected override string CreatePagerURL(string pageIndex)
        {
            string path = GetPath();
           
            if (path.IndexOf("?") > 0)
            {
                path += "&";
            }
            else
            {
                path += "?";
            }
            return path + "PageIndex=" + pageIndex;
        }

        private string GetPath()
        {
            string path = "";
            switch (pager)
            {
                case "CompanyAlbum":
                    {
                        path = SiteUrls.Instance().GetCompanyAlbumListUrl(greenNum);
                    }
                    break;
                case "CompanyBrand":
                    {
                        path = SiteUrls.Instance().GetCompanyBrandListUrl(greenNum);
                    }
                    break;
                case "CompanyNewsComment":
                    {
                        path = SiteUrls.Instance().GetCompanyNewsCommentListUrl(greenNum, commentId);
                    }
                    break;
                case "CompanyProductSearchResult":
                    {
                        path = SiteUrls.Instance().GetCompanyProductSearchResultUrl(area, level, productCategoryId, tradeType, queryText, provinceId, cityId, townId, smallTownId, orderBy, ascStr);
                    }
                    break;
                case "CompanyProject":
                    {
                        path = SiteUrls.Instance().GetCompanyProjectListUrl(greenNum);
                    }
                    break;
                case "CompanyProjectPerformance":
                    {
                        path = SiteUrls.Instance().GetCompanyProjectPerformanceListUrl(greenNum);
                    }
                    break;
                case "CompanyRecruit":
                    {
                        path = SiteUrls.Instance().GetCompanyRecruitListUrl(greenNum);
                    }
                    break;
                case "CompanySearchResult":
                    {
                        path = SiteUrls.Instance().GetCompanySearchResultUrl(area, level, companyType, companyName, greenNum, mobilePhoneKey, provinceId, cityId, townId, smallTownId);
                    }
                    break;
                case "CompanyTechnology":
                    {
                        path = SiteUrls.Instance().GetCompanyTechnologyListUrl(greenNum);
                    }
                    break;
                case "CompanyZiCai":
                    {
                        path = GetUserZiCaiListUrl(zicaiTopLevelCategoryID, zicaiSecondLevelCategoryID);
                    }
                    break;
                case "CompanyZiCai2":
                    {
                        path = GetUserZiCaiList2Url(zicaiTopLevelCategoryID, zicaiSecondLevelCategoryID);
                    }
                    break;
                case "MyCompanyAnonymousInfo":
                    {
                        path = SiteUrls.Instance().GetMyCompanyAnonymousInfoListUrl(greenNum);
                    }
                    break;
                case "MyCompanyInfo":
                    {
                        path = SiteUrls.Instance().GetMyCompanyInfoListUrl(greenNum);
                    }
                    break;
                case "MyCompanyShop":
                    {
                        path = SiteUrls.Instance().GetMyCompanyShopListUrl(greenNum);
                    }
                    break;
                case "MyShopping":
                    {
                        path = SiteUrls.Instance().GetMyShoppingListUrl(greenNum);
                    }
                    break;
                case "NewsComment":
                    {
                        path = SiteUrls.Instance().GetNewsCommentListUrl(greenNum, commentId);
                    }
                    break;
                case "TradeArticle":
                    {
                        path = SiteUrls.Instance().GetTradeArticleListUrl(greenNum);
                    }
                    break;
                case "UserArticle":
                    {
                        path = SiteUrls.Instance().GetUserArticleListUrl(greenNum);
                    }
                    break;
                case "UserCertificate":
                    {
                        path = SiteUrls.Instance().GetUserCertificateListUrl(greenNum);
                    }
                    break;
                case "UserContact":
                    {
                        path = SiteUrls.Instance().GetUserContactInfoUrl(greenNum);
                    }
                    break;
                case "ZiCaiSearchResult":
                    {
                        path = SiteUrls.Instance().GetZiCaiSearchResultUrl(area, level, zicaiTopLevelCategoryID, zicaiSecondLevelCategoryID, tradeType, queryText, provinceId, cityId, townId, smallTownId, kind, defaultIndex);
                    }
                    break;
                case "CompanyProduct":
                    {
                        #region CompanyProduct

                        if (tradeType == "0")
                        {
                            path = SiteUrls.Instance().GetUserProductListUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "1")
                        {
                            path = SiteUrls.Instance().GetUserProductListJPUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "2")
                        {
                            path = SiteUrls.Instance().GetUserProductListQGUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "3")
                        {
                            path = SiteUrls.Instance().GetUserProductListJSUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }

                        #endregion
                    }
                    break;
                case "CompanyProduct2":
                    {
                        #region CompanyProduct2

                        if (tradeType == "0")
                        {
                            path = SiteUrls.Instance().GetUserProductList2Url(greenNum, categoryId, appCategoryId, categoryType, orderBy, ascStr);
                        }
                        else if (tradeType == "1")
                        {
                            path = SiteUrls.Instance().GetUserProductListJP2Url(greenNum, categoryId, appCategoryId, categoryType, orderBy, ascStr);
                        }
                        else if (tradeType == "2")
                        {
                            path = SiteUrls.Instance().GetUserProductListQG2Url(greenNum, categoryId, appCategoryId, categoryType, orderBy, ascStr);
                        }
                        else if (tradeType == "3")
                        {
                            path = SiteUrls.Instance().GetUserProductListJS2Url(greenNum, categoryId, appCategoryId, categoryType, orderBy, ascStr);
                        }

                        #endregion
                    }
                    break;
                case "CompanyFishery":
                    {
                        #region CompanyFishery

                        if (tradeType == "0")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "1")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListJPUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "2")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListQGUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "3")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListJSUrl(greenNum, categoryId, appCategoryId, categoryType);
                        }

                        #endregion
                    }
                    break;
                case "CompanyFishery2":
                    {
                        #region CompanyFishery2

                        if (tradeType == "0")
                        {
                            path = SiteUrls.Instance().GetUserFisheryList2Url(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "1")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListJP2Url(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "2")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListQG2Url(greenNum, categoryId, appCategoryId, categoryType);
                        }
                        else if (tradeType == "3")
                        {
                            path = SiteUrls.Instance().GetUserFisheryListJS2Url(greenNum, categoryId, appCategoryId, categoryType);
                        }

                        #endregion
                    }
                    break;
                case "Aquaculture":
                    {
                        #region Aquaculture

                        path = SiteUrls.Instance().GetTechDefaultUrl();

                        if (aquacultureKebieId > 0)
                        {
                            path = SiteUrls.Instance().GetTechListUrl(aquacultureKebieId, categoryType);
                        }
                        else if (!string.IsNullOrEmpty(character))
                        {
                            path = SiteUrls.Instance().GetTechListUrl(character, categoryType);
                        }
                        if (!string.IsNullOrEmpty(queryText))
                        {
                            if (path.IndexOf("?") > 0)
                            {
                                path += string.Format("&QueryText={0}", System.Web.HttpUtility.UrlEncode(queryText));
                            }
                            else
                            {
                                path += string.Format("?QueryText={0}", System.Web.HttpUtility.UrlEncode(queryText));
                            }
                        }

                        #endregion
                    }
                    break;
                case "Article":
                    {
                        #region Article

                        path = SiteUrls.Instance().GetArticleListUrl(upNewsCategoryId);
                        if (path.IndexOf("?") > 0)
                        {
                            path += "&";
                        }
                        else
                        {
                            path += "?";
                        }
                        if (!string.IsNullOrEmpty(queryText))
                        {
                            path += string.Format("QueryText={0}", System.Web.HttpUtility.UrlEncode(queryText));
                        }

                        #endregion
                    }
                    break;
                case "Product":
                    {
                        #region Product

                        path = SiteUrls.Instance().GetTechDefaultUrl();
                        if (miaoMuCategoryId > 0)
                        {
                            path = SiteUrls.Instance().GetTechListUrl(miaoMuCategoryId, categoryType);
                        }
                        else if (!string.IsNullOrEmpty(character))
                        {
                            path = SiteUrls.Instance().GetTechListUrl(character, categoryType);
                        }
                        if (!string.IsNullOrEmpty(queryText))
                        {
                            if (path.IndexOf("?") > 0)
                            {
                                path += string.Format("&QueryText={0}", System.Web.HttpUtility.UrlEncode(queryText));
                            }
                            else
                            {
                                path += string.Format("?QueryText={0}", System.Web.HttpUtility.UrlEncode(queryText));
                            }
                        }

                        #endregion
                    }
                    break;
            }
            return path;
        }
        private string GetUserZiCaiListUrl(int topCategoryId, int secondCategoryId)
        {
            string str = string.Empty;
            if (kind == 1)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyMachineChuShouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyMachineQiuGouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
            }
            else if (kind == 2)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyFacilityChuShouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyFacilityQiuGouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
            }
            else if (kind == 3)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyAgriculturalChuShouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyAgriculturalQiuGouListUrl(greenNum, topCategoryId, secondCategoryId);
                }
            }

            return str;
        }
        private string GetUserZiCaiList2Url(int topCategoryId, int secondCategoryId)
        {
            string str = string.Empty;
            if (kind == 1)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyMachineChuShouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyMachineQiuGouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
            }
            else if (kind == 2)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyFacilityChuShouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyFacilityQiuGouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
            }
            else if (kind == 3)
            {
                if (tradeType == "0")
                {
                    str = SiteUrls.Instance().GetCompanyAgriculturalChuShouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
                else if (tradeType == "1")
                {
                    str = SiteUrls.Instance().GetCompanyAgriculturalQiuGouList2Url(greenNum, topCategoryId, secondCategoryId);
                }
            }

            return str;
        }
    }
}
